using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.U2D;
using UnityEngine.UI;

public class Health : MonoBehaviour
{
    public GameObject canvas = null;
    // Start is called before the first frame update
    void Awake()
    {
        AdManager.Instance.InitData();
    }
    void Start()
    {
        AdManager.Instance.InitData();
        // PlayerPrefs.DeleteAll();
        Changge_Agelimit();
        Changge_ZhuZuoQuan();
        if (!PrefsManager.GetBool("Privacy"))
        {
            PrivacyPanel.Show(canvas.transform);
        }
        Hide();
    }

    //判断隐私
    void Hide()
    {
        if (!PrefsManager.GetBool("Privacy"))
        {
            Invoke("Hide", 1);
        }
        else
        {
            GoMain();
        }
    }

    //延迟2秒入主场景
    void GoMain()
    {
        Invoke("_goMain", 1);
    }
    void _goMain()
    {
        SceneManager.LoadScene("Start");
    }

    //更新著作权信息
    void Changge_ZhuZuoQuan()
    {
        canvas.transform.Find("著作人").GetComponent<Text>().text = AdManager.Owner + "\n" + AdManager.License;
    }

    //更换年龄
    void Changge_Agelimit()
    {
        int index = 0;
        if (AdManager.AgeLimit == 12) index = 1;
        if (AdManager.AgeLimit == 16) index = 2;
        Sprite[] a = Resources.LoadAll<Sprite>("Sprites/AgeLimit");
        canvas.transform.Find("适龄").GetComponent<Image>().sprite = a[index];
    }

}
